home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Workbench1.3 / Ieee.Examples / Div0 / div0.c next >
Encoding:
C/C++ Source or Header  |  1988-02-11  |  959 b   |  55 lines

  1.  
  2. #include <exec/types.h>
  3. #include "setjmp.h"
  4.  
  5. #define    SIGDIV0    5
  6. #define SIGTRAPV        7
  7. #define SIGFPCP_DIVIDEBY0       50
  8. #define SIGFPCP_OVERFLOW        53
  9.  
  10. jmp_buf div0_buf;
  11.  
  12. long    MathIeeeDoubBasBase = 0;
  13.  
  14. SigTrap0()
  15. {
  16.     printf("divide by zero caught\n");
  17.     longjmp(div0_buf, 1);
  18. }
  19.  
  20. DOUBLE    zero = 0.0;
  21. DOUBLE    one = 1.0;
  22. DOUBLE    result;
  23.  
  24. main(argc,argv)
  25. {
  26.     printf(" Test Divide by zero handling\n");
  27.  
  28.     MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",0);
  29.  
  30.     if (!MathIeeeDoubBasBase)
  31.     {
  32.         printf(" could not open Mathieeedoubbas.library\n");
  33.         exit(-1);
  34.     }
  35.  
  36.     /* first set up Intercept routine */
  37.  
  38.     InterceptTrap(SIGDIV0, SigTrap0);    /* for 68000/68010 */
  39.     InterceptTrap(SIGFPCP_DIVIDEBY0, SigTrap0);    /* 68020 */
  40.  
  41.     if (setjmp(div0_buf)) goto caught_div0;
  42.  
  43.     result = one/zero;
  44.  
  45.     printf("H'mmm, no error? , oh well\n");
  46.         goto exit;
  47.  
  48. caught_div0:
  49.     printf(" back in main program, and NO guru \n");
  50.  
  51. exit:
  52.     CloseLibrary(MathIeeeDoubBasBase);
  53.     exit(0);
  54. }
  55.